/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Gui;

import java.sql.Connection;
import java.util.HashMap;
import net.sf.jasperreports.engine.*;

/**
 *
 * @author Rainiero
 */
public class ReportHelper {

    public static String ShowReport(String address, Connection connection)
    {
        String error = "";
        try
        {
            String path = String.format("C:\\Users\\Rainiero\\Documents\\NetBeansProjects\\SAFP\\SAFP\\SAFP-war\\web\\Reports\\%1$s", address);
            System.setProperty("java.awt.headless", "true");
            JasperPrint print = JasperFillManager.fillReport(path + ".jasper", new HashMap(), connection);
            // Exporta el informe a PDF
            JasperExportManager.exportReportToPdfFile(print, path + ".pdf");
            //Para visualizar el pdf directamente desde java
        }
        catch(Exception ex)
        {
            error = "Error al tratar de exportar a PDF: " + ex.getMessage();
        }
        return error;
    }

}
